var currentPage=1;
var jName = getCookie('Jname');
var type = -1;
//var jName = getCookie('Jname');
//我的权限数组
var arrayTitle = new Array; 
$(document).ready(function() {
	findMyCatalogue();
	init(currentPage);
});
//默认加载  
function init(pageNo){
	
	PageClick = function(pageclickednumber) {
		init(pageclickednumber);
	}	
	
	//获取信息列表
	$("#thislist").html("");
	$.ajax({
		url: urlcore + "/api/helpCenter/selectPage?current="+pageNo+"&type="+type,
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		async: false,
		success:function(data){
			if (data.success == true) {
				//i表示在data中的索引位置，n表示包含的信息的对象
				$.each(data.data.records,function(i,n){	
					var typeTitle = "";
					if (n.type == 1) {
						typeTitle = "认证攻略";
					}else if(n.type == 2){
						typeTitle = "借款攻略";
					}else if(n.type == 3){
						typeTitle = "业务介绍";
					}else if(n.type == 4){
						typeTitle = "申请借款";
					}else if(n.type == 5){
						typeTitle = "还款相关";
					}else if(n.type == 6){
						typeTitle = "协议相关";
					}else if(n.type == 7){
						typeTitle = "权限管理";
					}else if(n.type == 8){
						typeTitle = "联系客服";
					}
					else{
						typeTitle = "其他分类";
					}
					var thislist = 
					'	<tr>'+				
					'		<td>'+n.id+'</td>'+
					'		<td>'+typeTitle+'</td>'+
					'		<td>'+n.title+'</td>'+
					'		<td>'+
                    '           <a  name="查看/修改" class="" hidden="hidden" href="help_center_add.html?id='+n.id+'">查看/修改</a>'+
// 					'           <a  name="删除" class="btn btn-primary btn-xs" href="javascript:;" onclick="deleteeach('+n.id+')">删除</a>'+						
					'		</td>'+	
					'	</tr>';
					$('#thislist').append(thislist);														
				});
				$("#pager").pager({ 
					pagenumber: pageNo,
					pagecount: data.data.pages,
					totalcount: data.data.total,
					buttonClickCallback:PageClick
				});  
				  
			} else if (data.code == 'OVERTIME'){
				var thisUrl = window.location.href;
				if (thisUrl.indexOf('login.html') <= -1) {
					top.window.location.href="login.html";
				}

			} else { 
				if (data.msg != '空数据') {
					alert(data.msg)
				}else{
					$('#thiscount').text(0);
				}
			}

		},
	});
	
}
 
 function searchList (){
 	type = $('#type').val();
 	init(currentPage);
 }
 

function deleteeach(id){
	 if(confirm("您确定删除吗？")) {
		$.ajax({
	        url: urlcore + "/api/helpCenter/deleteOne?id="+id,
	        type: "get",
	        dataType: 'json',
	        contentType: "application/json;charset=utf-8",
	        success:function(data){
	            if (data.success == true) {
	            	location.reload();
	            } else if (data.code == 'OVERTIME'){
	                var thisUrl = window.location.href;
	                if (thisUrl.indexOf('login.html') <= -1) {
	                    top.window.location.href="login.html";
	                }
	            } else {
	                alert(data.msg);
	            }
	        },
	        error:function() {
	            /* Act on the event */
	            alert("error");
        }
    });
}
	 }


/**
 * 用户状态返回
 * @param {Object} type
 */
function typeStr(type){
	if(type==1) {
		type = '贷款攻略';
	}
	else if(type==2) {
		type = '信用生活';
	}
	else if(type==3) {
		type = '办卡攻略';
	}
	else if(type==4) {
		type = '羊毛活动';
	}
	return type;
}


function findMyCatalogue(){
	$.ajax({
		url: urlcore + "/api/roleThirdCatalogue/findAllByUser?secondTitle="+jName,
		type: "GET",
		dataType: 'json',
		async: false,
		contentType: "application/json;charset=utf-8",
		success:function(data){
		if (data.success == true) {
			$.each(data.data, function(i,n) {
				arrayTitle.push(n.thirdCatalogue.title);
			});
		} else {
			alert(data.msg);
		}

		},
		error:function() {
			alert("error");
		}
	});
}

